package com.haier.npt.filter.authorization;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.Route;
import org.springframework.stereotype.Component;

import com.haier.npt.authention.authc.RequestContextInfo;
import com.haier.npt.authention.support.PermissionSupport;
import com.haier.npt.security.domain.SysPermission;

@Component
public  class AbstractAuthProvider {

    @Autowired
    protected PermissionSupport permissionSupport;

    @Autowired
    protected RequestContextInfo requestContextInfo;

    /**
     * 获取当前人的权限项
     *
     * @return
     */
    public List<SysPermission> onAuthorization(HttpServletRequest request, Route route) {

        Long userId = requestContextInfo.getUserid();
        return this.listPermissionByUserId(userId);
    }



    /**
     * 查询用户当前的权限
     *
     * @param userId   当前用户id
     * @return
     */
    protected List<SysPermission> listPermissionByUserId(Long userId) {
        List<SysPermission> permissionList = permissionSupport.listPermissionByUserId(userId, requestContextInfo.getToken());
        return permissionList;
    }
}
